home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_300 / 343_02 / mainhist.c < prev    next >
C/C++ Source or Header  |  1992-03-17  |  4KB  |  134 lines

  1.  
  2.  
  3.  
  4.  
  5.        /***********************************************
  6.        *
  7.        *       file d:\cips\mainhist.c
  8.        *
  9.        *       Functions: This file contains
  10.        *          main
  11.        *
  12.        *       Purpose:
  13.        *          This file contains the main calling
  14.        *          routine which will perform histogram
  15.        *          equalization on an input image to
  16.        *          produce an output image.
  17.        *
  18.        *       External Calls:
  19.        *          gin.c - get_image_name
  20.        *          numcvrt.c - get_integer
  21.        *                      int_convert
  22.        *          tiff.c - read_tiff_header
  23.        *            rtiff.c - read_tiff_image
  24.        *            wtiff.c - write_array_into_tiff_image
  25.        *            hist.c - calculate_histogram
  26.        *                     zero_histogram
  27.        *                     perform_histogram_equalization
  28.        *
  29.        *       Modifications:
  30.        *          17 March 1992 - created  
  31.        *
  32.        *************************************************/
  33.  
  34. #include "d:\cips\cips.h"
  35.  
  36.  
  37.  
  38. short the_image[ROWS][COLS];
  39. short out_image[ROWS][COLS];
  40.  
  41. main(argc, argv)
  42.    int argc;
  43.    char *argv[];
  44. {
  45.  
  46.    char name[80], name2[80];
  47.    float new_grays, area;
  48.    int  count, i, ie, il, j, le, length, ll, size,
  49.         t, type, v, width, x, y;
  50.  
  51.    unsigned long histogram[256], new_hist[256];
  52.  
  53.  
  54.    struct   tiff_header_struct image_header;
  55.  
  56.    _setvideomode(_TEXTC80); /* MSC 6.0 statements */
  57.    _setbkcolor(1);
  58.    _settextcolor(7);
  59.    _clearscreen(_GCLEARSCREEN);
  60.  
  61.    if(argc < 3){
  62.     printf("\n\nNot enough parameters:");
  63.     printf("\n");
  64.     printf("\n   usage: mainhist in-file out-file  ");
  65.     exit(0);
  66.    }
  67.  
  68.    strcpy(name, argv[1]);
  69.    strcpy(name2, argv[2]);
  70.  
  71.    if(does_not_exist(name2)){
  72.       read_tiff_header(name, &image_header);
  73.       round_off_image_size(&image_header,
  74.                            &length, &width);
  75.       image_header.image_length = length*ROWS;
  76.       image_header.image_width  = width*COLS;
  77.       create_allocate_tiff_file(name2, &image_header,
  78.                                 the_image);
  79.    }  /* ends if does_not_exist */
  80.  
  81.  
  82.    il = 1;
  83.    ie = 1;
  84.    ll = ROWS+1;
  85.    le = COLS+1;
  86.  
  87.    read_tiff_header(name, &image_header);
  88.  
  89.    length = (90 + image_header.image_length)/ROWS;
  90.    width  = (90 +image_header.image_width)/COLS;
  91.    count  = 1;
  92.    printf("\nlength=%d  width=%d", length, width);
  93.  
  94.    zero_histogram(histogram);
  95.    zero_histogram(new_hist);
  96.  
  97.  
  98.    for(i=0; i<length; i++){
  99.       for(j=0; j<width; j++){
  100.         printf("\nCalculating Histogram %d of %d", count, length*width);
  101.         count++;
  102.  
  103.          read_tiff_image(name, the_image, il+i*ROWS,
  104.                         ie+j*COLS, ll+i*ROWS, le+j*COLS);
  105.          calculate_histogram(the_image, histogram);
  106.  
  107.  
  108.       } /* ends loop over j */
  109.    }  /* ends loop over i */
  110.  
  111.  
  112.    area      = ((long)(length))*((long)(width));
  113.    area      = area*10000.0;
  114.    new_grays = 250;
  115.  
  116.    count = 1;
  117.  
  118.    for(i=0; i<length; i++){
  119.       for(j=0; j<width; j++){
  120.         printf("\nDoing equalization %d of %d", count, length*width);
  121.         count++;
  122.  
  123.          read_tiff_image(name, the_image, il+i*ROWS,
  124.                         ie+j*COLS, ll+i*ROWS, le+j*COLS);
  125.          perform_histogram_equalization(the_image, histogram,
  126.                                           new_grays, area);
  127.          write_array_into_tiff_image(name2, the_image,
  128.                                      il+i*ROWS, ie+j*COLS, 
  129.                                     ll+i*ROWS, le+j*COLS);
  130.       } /* ends loop over j */
  131.    }  /* ends loop over i */
  132.  
  133. }  /* ends main  */
  134.